import time

import allure
from selenium.webdriver.common.by import By

from po.page.base_page import BasePage
from po.utils.log_utils import logger


class AddMemberPage(BasePage):
    _NAME = By.ID, "username"
    _ACCID = By.ID, "memberAdd_acctid"
    _PHONE_NUMBER = By.ID, "memberAdd_phone"
    _SAVE_BTN = By.XPATH, '(//*[text()="保存"])[2]'

    @allure.step("输入成员信息,保存成功")
    def add_member_success(self, name, accid, phone_number):
        """
        添加成员成功
        :return:
        """
        self.wait_locate(*self._NAME)
        # 输入姓名
        self.find_ele(*self._NAME).send_keys(name)
        # 输入账号
        self.find_ele(*self._ACCID).send_keys(accid)
        # 输入手机号
        self.find_ele(*self._PHONE_NUMBER).send_keys(phone_number)
        # 点击保存
        time.sleep(2)
        self.find_ele(*self._SAVE_BTN).click()
        time.sleep(2)
        logger.info("添加成员成功，返回通讯录页面")
        from po.page.contact_page import ContactPage
        return ContactPage(self.driver)

